print("Hello World")

local a = 1
local b = 2
print(a + b)


Shape = {class = 'Shape'}
Shape.__index = Shape
function Shape:new(name)
    local o = {}
    o.name = name
    o.class = {self.class}
    setmetatable(o, self)
    return o
end

function Shape:print()
    print("This is a shape:" .. self.name)
end

function Shape:area()
    error("area() method must be overridden")
end

Rectangle = Shape:new() -- 继承
Rectangle.class = 'Rectangle'
Rectangle.__index = Rectangle

function Rectangle:new(width, height)
    local o = Shape:new("Rectangle")
    setmetatable(o, self)
    o.width = width
    o.height = height
    o.name = "My Rect"
    table.insert(o.class, 1, self.class)
    return o
end

function Rectangle:area()
    return self.width * self.height
end

function Rectangle:print()
    Shape.print(self)
    print("This is a rectangle with width " .. self.width .. " and height " .. self.height)
end

local r = Rectangle:new(10, 20)
r:print()
print(r:area())

print("-------r.class----------")
local mt = getmetatable(r)
for index, value in ipairs(r.class) do
    print(index, value, 'matatable:', mt.class)
    mt = getmetatable(mt)
end